package huytq.gs.view;

import java.util.ArrayList;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.WakeLockOptions;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.ui.activity.SimpleLayoutGameActivity;

import tronglv.gs.view.ChonBanAdapter;
import tronglv.gs.view.ChonTuongAdapter;
import tronglv.gs.view.ThanhTichAdapter;

import com.example.paralletkill.R;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.AdapterView.OnItemClickListener;

public class ChonDiaDiem extends SimpleLayoutGameActivity implements AnimationListener , OnClickListener{
	
	private static final int WIDTH = 800;
    private static final int HEIGHT = 480;
   
    private Scene _scene;
    private Camera _camera;
	
	private MyGallery mGallery;
	private Activity activity;
//	Animation a;
	
//	public static TextView tv_ten;
	
	public ChonDiaDiem(Activity activity) {
		// TODO Auto-generated constructor stub
		this.activity = activity;
		this.activity.setContentView(R.layout.chondiadiem);
	}
	
	@Override
	public EngineOptions onCreateEngineOptions() {
		_camera = new Camera(0, 0, WIDTH, HEIGHT);
        EngineOptions engineOptions = new EngineOptions(true,
                        ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(), _camera);
        engineOptions.setWakeLockOptions(WakeLockOptions.SCREEN_ON);
		return engineOptions;
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAnimationRepeat(Animation animation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAnimationStart(Animation animation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void onCreateResources() {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected Scene onCreateScene() {
		_scene = new Scene();
//		tv_ten = (TextView) findViewById(R.id.tv_ten);
		
		
		
		return _scene;
	}

	@Override
	protected int getLayoutID() {
		// TODO Auto-generated method stub
		return R.layout.chondiadiem;
	}

	@Override
	protected int getRenderSurfaceViewID() {
		// TODO Auto-generated method stub
		return R.id.andengine_rendersurfaceview;
	}
	
	public void CreatChonDiaDiem(){
		runOnUiThread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				mGallery = (MyGallery)activity.findViewById(R.id.Gallery01);
				mGallery.setAdapter(new ImageAdapter(activity));
				mGallery.setOnItemClickListener(new OnItemClickListener(){

					public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
						 Animation animation = AnimationUtils.loadAnimation(ChonDiaDiem.this.activity, R.anim.anim);
						 animation.setAnimationListener(ChonDiaDiem.this);
						 view.startAnimation(animation);
						 // goi view cua tien o day
						 activity.setContentView(R.layout.activity_main);
						 ChonDiaDiem.this.initButton();
					}
				});
			}
		});
	}
	EditText ed;
	public void initButton(){
	   
	    creatTab();
		final Button b = (Button)activity.findViewById(R.id.button1);
		final Button b1 = (Button)activity.findViewById(R.id.button2);
		final Button b3 = (Button)activity.findViewById(R.id.button3);
		final Button b4 = (Button)activity.findViewById(R.id.button4);
		final Button b5 = (Button)activity.findViewById(R.id.button5);
		final View view = (View)activity.findViewById(R.id.infobulle);
		final View view1 = (View)activity.findViewById(R.id.infobulle1);
		final View view2 = (View)activity.findViewById(R.id.infobulle2);
		final View view3 = (View)activity.findViewById(R.id.infobulle3);
		Gallery gv = (Gallery)activity.findViewById(R.id.gallery1);
		gv.setAdapter(new ChonTuongAdapter(ChonDiaDiem.this.activity, new ArrayList<String>()));
		GridView gv1 = (GridView)activity.findViewById(R.id.gridView1);
		gv1.setAdapter(new ChonBanAdapter(ChonDiaDiem.this.activity, new ArrayList<String>()));
		ListView lv1 = (ListView)activity.findViewById(R.id.lv_thanhtich);
		lv1.setAdapter(new ThanhTichAdapter(ChonDiaDiem.this.activity, new ArrayList<String>()));
		lv1.setDividerHeight(0);
		b.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				view1.setVisibility(View.VISIBLE);
				view.setVisibility(View.GONE);
				view2.setVisibility(View.GONE);
				view3.setVisibility(View.GONE);
				b.setBackgroundResource(R.drawable.bt_ena);
				b1.setBackgroundResource(R.drawable.bt_dis);
				b4.setBackgroundResource(R.drawable.bt_dis);
				b3.setBackgroundResource(R.drawable.bt_dis);
				b5.setBackgroundResource(R.drawable.bt_dis);
			}
		});
		b1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				view1.setVisibility(View.GONE);
				view.setVisibility(View.VISIBLE);
				view2.setVisibility(View.GONE);
				view3.setVisibility(View.GONE);
				b1.setBackgroundResource(R.drawable.bt_ena);
				b.setBackgroundResource(R.drawable.bt_dis);
				b4.setBackgroundResource(R.drawable.bt_dis);
				b3.setBackgroundResource(R.drawable.bt_dis);
				b5.setBackgroundResource(R.drawable.bt_dis);
			}
		});
		b3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				view1.setVisibility(View.GONE);
				view.setVisibility(View.GONE);
				view2.setVisibility(View.VISIBLE);
				view3.setVisibility(View.GONE);
				b3.setBackgroundResource(R.drawable.bt_ena);
				b1.setBackgroundResource(R.drawable.bt_dis);
				b4.setBackgroundResource(R.drawable.bt_dis);
				b.setBackgroundResource(R.drawable.bt_dis);
				b5.setBackgroundResource(R.drawable.bt_dis);
			}
		});
		b4.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				view1.setVisibility(View.GONE);
				view.setVisibility(View.GONE);
				view2.setVisibility(View.GONE);
				view3.setVisibility(View.VISIBLE);
				b4.setBackgroundResource(R.drawable.bt_ena);
				b1.setBackgroundResource(R.drawable.bt_dis);
				b.setBackgroundResource(R.drawable.bt_dis);
				b3.setBackgroundResource(R.drawable.bt_dis);
				b5.setBackgroundResource(R.drawable.bt_dis);
			}
		});
		ImageView iv_avatar = (ImageView)activity.findViewById(R.id.iv_avatar);
		iv_avatar.setOnClickListener(this);
	}
	
	public void creatTab(){
			TabHost mTabHost = (TabHost)activity.findViewById(R.id.tabhost1);
		    mTabHost.setup();
		    mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Cấp độ").setContent(R.id.vl1));
		    mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Thắng").setContent(R.id.vl1));
		    mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Vàng").setContent(R.id.vl1));
		    mTabHost.addTab(mTabHost.newTabSpec("tab4").setIndicator("Thua").setContent(R.id.vl1));
		    mTabHost.addTab(mTabHost.newTabSpec("tab5").setIndicator("Thành Tích").setContent(R.id.vl1));
		    mTabHost.setCurrentTab(0);

	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Dialog d = new Dialog(ChonDiaDiem.this.activity,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
		d.setContentView(R.layout.dialog_changeprofile);
		d.show();
		
	}
}
